
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>新建帖子</title>
  <link rel="stylesheet" href="${request.contextPath}/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${request.contextPath}/layFly/css/global.css">
</head>
<body>

<div class="layui-container fly-marginTop">
  <div class="fly-panel" pad20 style="padding-top: 5px;margin-top: 30px">
    <!--<div class="fly-none">没有权限</div>-->
    <div class="layui-form layui-form-pane">
      <div class="layui-tab layui-tab-brief" lay-filter="user">
        <ul class="layui-tab-title">
          <li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
        </ul>
        <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
          <div class="layui-tab-item layui-show">
            <form action="" method="post">
              <input type="text"  name="id" autocomplete="off" class="layui-input" style="display: none">
              <div class="layui-row layui-col-space15 layui-form-item">
                <div class="layui-col-md12">
                  <label for="L_title" class="layui-form-label">标题</label>
                  <div class="layui-input-block">
                    <input type="text" id="L_title" name="title" required lay-verify="required" autocomplete="off" class="layui-input">
                    <!-- <input type="hidden" name="id" value="{{d.edit.id}}"> -->
                  </div>
                </div>
                <div class="layui-form-item layui-form-text">
                  <div class="layui-input-block">
                    <textarea id="content" name="content" class="layui-textarea" placeholder="请输入内容"></textarea>
                  </div>
                </div>
                <div class="layui-col-md12">
                  <label for="L_title" class="layui-form-label">作品选择</label>
                  <div class="layui-input-block">
                    <select id="piece" name="url" lay-verify="required">

                    </select>
                  </div>
                </div>
              </div>

              <div class="layui-form-item">
                <button class="layui-btn" lay-filter="submit" lay-submit>立即发布</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="fly-footer">
  <p>MNM社区 2021 &copy; </p>

</div>

<script src="${request.contextPath}/layuiadmin/layui/layui.js"></script>
<script>
layui.use(['form'],function () {
  var $ = layui.$;
  var form=layui.form;
  //回显作品选项
  $.ajax({
    type:"post",
    url: "${request.contextPath}/piece/getAll?userId=${(user.id)!}",
    async:false,
    contentType:'application/json; charset=UTF-8',
    success: function(res) {
      console.log(res)
      var data=res.data
      var html='<option value="">请选择</option>'
      for(var i=0;i<data.length;i++){
        var item=data[i]
        html=html+'<option value="'+item.url+'">'+item.name+'</option>'
      }
      $("#piece").html(html)
      form.render()
    },
    error: function(res) {
      layer.alert(res.msg,{icon:2})
    }
  })

  form.on('submit(submit)', function(data){
    console.log(data.field);
    $.ajax({
      type:"post",
      url: "${request.contextPath}/forum/saveItem",
      contentType:'application/json; charset=UTF-8',
      data: JSON.stringify(data.field),
      // data: {customer:data.field},
      // data:data.field,
      success: function(res) {
        console.log("=====success=====")
        console.log(res)
        if(res.code===200){
          layer.alert(res.msg,{icon:1},function () {
            //保存后跳转论坛页面。
            window.location.href="${request.contextPath}/to/forum"
          })
        }
      },
      error: function(res) {
        layer.alert(res.msg,{icon:2})
      }
    })
    return false;
  });
});
</script>

</body>
</html>